
# 1、编译初始化
DEBUG ?= 0	# 调试日志开关
UNIT_TEST ?= 0			# 单元测试

COMPILE_TIME := $(shell date +"%Y-%m-%d_%H_%M_%S")
GXX = g++
STRIP = strip
RM = rm -rf
CXXFLAGS = -std=c++11 -lmuduo_base -lmuduo_net

# 2、源文件
LIB=lib
INCLUDE=include
SRC = src/common/common.cpp \
		src/protocol_business/protocol.cpp \
		src/protocol_business/protocol_engine.cpp \
		src/protocol_business/protocol_business.cpp

# 3、单元测试选择
ifeq ($(UNIT_TEST), 1)
	SRC += unit_test/test.cpp \
		unit_test/unit_test_main.cpp

	CXXFLAGS += -lgtest -pthread
else
	SRC += main.cpp
endif

# 4、日志开关
ifeq ($(DEBUG), 1)
CXXFLAGS += -DDEBUG_LOG_ENABLE
endif

# 5、编译
OBJS = $(patsubst %cpp, %o, $(SRC))
BIN=main-$(COMPILE_TIME)
all:$(OBJS)
	$(GXX) $(OBJS) -o $(BIN) -I $(INCLUDE) -L $(LIB) $(CXXFLAGS)
	$(STRIP) $(BIN)

# 6、编译CPP
$(OBJS):%.o:%.cpp
	$(GXX) -c $< -o $@ $(CXXFLAGS) -I $(INCLUDE) -L $(LIB)

# 7、清除
clean:
	$(RM) $(BIN) main-* $(OBJS)

# 8、安装
install:
	# cp -rf $(BIN) ~

# 9、.PHONE伪目标，避免与文件同名
.PHONY:all clean install
